const config = require("../config/config.js");
const URI = config.uri;
//网络请求模块
exports.request = function(params){
	let url = URI + params.url;                             //请求参数
	let method = params.method ? params.method : "POST";    //默认为POST请求方式
	let headers = {
		'Content-Type': 'application/x-www-form-urlencoded' //默认为form格式
	};
	let formData = new FormData();
	for(var item in params.body){
		formData.append(item, params.body[item]);
	};
	fetch(url, {
		method: method,
		headers: headers,
		body: formData
	})
	.then((response)=>response.json())
	.then((result)=>{
		console.log(result);
		if(params.success){
			params.success(result);
		};
	})
	.catch((error)=>{
		console.log("error");
		if(params.fail){
			params.fail(error);
		};
	});
};